package ws.jdbc.concurrent.driver.sqlserver.tds.rpc;

import java.nio.ByteBuffer;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.VARLENTYPE;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class ParameterData {

  /**
   * Parameter meta data.
   */
  private ParamMetaData meta;
  /**
   * Parameter data.
   */
  private ParamLenData data;

  protected ParameterData() {
  }

  public ParameterData(byte statusFlags, int data) {
    this.data = new ParamLenData(data);
    this.meta = new ParamMetaData(statusFlags, VARLENTYPE.INTTYPE, this.data.getTypeVarLen());
  }

  public ParameterData(byte statusFlags, byte varlentype, int type_varlen, String data, byte[] collation) {
    this.meta = new ParamMetaData(statusFlags, varlentype, type_varlen, collation);
    this.data = new ParamLenData(data, varlentype);
  }

  public int size() {
    return meta.size() + data.size();
  }

  public byte[] getBytes() {
    return ByteBuffer.allocate(size()).put(meta.getBytes()).put(data.getBytes()).array();
  }
}
